<template>
  <!-- 公安 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人" prop="opeUser">
        <el-input
          v-model="queryParams.opeUser"
          placeholder="请输入操作人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上传时间" prop="zjhm">
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:swmd:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:swmd:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:swmd:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:swmd:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportExample"
          v-hasPermi="['system:swmd:exportExample']"
        >下载模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <file-upload :isShowTip="isShowTip" :fileType="fileType"  v-hasPermi="['system:swmd:upload']" uploadUrl="/system/swmd/importData" @input="handleSucess"></file-upload>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="swmdList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="文件名称" align="center" prop="fileName" min-width="100"/>
      <el-table-column label="操作" align="center" prop="operate" />
      <el-table-column
        label="操作人"
        align="center"
        prop="opeUser"
        width="180"
      />
      <el-table-column
        label="操作结果"
        align="center"
        prop="opeResult"
        min-width="300"
      />
      <el-table-column
        label="操作时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.swsj, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="120"
        fixed="right"
        v-hasPermi="['system:logs:query']"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:swmd:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:swmd:remove']"
          >删除</el-button> -->
          <!-- v-hasPermi="['system:swmd:remove']" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-detail"
            v-hasPermi="['system:logs:query']"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <log-detail-dialog ref="logDetailDialog" />
  </div>
</template>

<script>
import LogDetailDialog from "./components/logDetail.vue";
import { listLog } from "@/api/system/list";
export default {
  name: "",
  components: {
    LogDetailDialog,
  },
  data() {
    return {
      isShowTip: true,
      fileType: ["xls", "xlsx"],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 逝亡信息表格数据
      swmdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        time: [],
        operate:"数据导入"
      },
      // 表单参数
      form: {},
      // 表单校验
      logDetailVisible: false, // 日志详情弹窗显示状态
      logDetailData: {}, // 日志详情数据
      logDetailLoading: false, // 加载状态
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSucess() {
      this.getList();
    },
    /** 查询逝亡信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.startTime = this.queryParams.time[0];
      this.queryParams.endTime = this.queryParams.time[1];
      listLog(this.queryParams).then((response) => {
        this.swmdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bgdqmc: null,
        bgbh: null,
        tbdwdm: null,
        tbdwmc: null,
        fileName: null,
        xb: null,
        zjlx: null,
        opeUser: null,
        csrq: null,
        mz: null,
        szxxdz: null,
        hjxxdz: null,
        swsj: null,
        swdd: null,
        jtfileName: null,
        jslxfs: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        time: [],
        operate:"数据导入"
      },
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加逝亡信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSwmd(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改逝亡信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateSwmd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSwmd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleDetail(row) {
      this.$refs.logDetailDialog.fetchDetail(row.id);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除逝亡信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delSwmd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/swmd/export",
        {
          ...this.queryParams,
        },
        `swmd_${new Date().getTime()}.xlsx`
      );
    },
    /* 下载模板 */
    handleExportExample() {
      this.download("system/swmd/importTemplate", {}, `GA_导入模板.xlsx`);
    },
  },
};
</script>
